#include "animation.h"
#include <stdlib.h>
#include "texture.h"
#include "frame.h"
#include "source.h"
 
Animation::Animation()
{
	nFrames =0;
	frames =NULL;
	sprites =NULL;
	sources =NULL;
	extra =NULL;
};

Animation::~Animation()
{
	unsigned int i;

	// delete frames
	//? frames may be used for other animations, but eventually someone should delete them
	delete[] frames;
	frames =NULL;

	// delete sprites
	// delete sources
	for(i=0; i<nFrames; i++){
		delete sprites[i];
		sprites[i] =NULL;

		delete sources[i];
		sources[i] =NULL;
	}
	delete[] sprites;
	sprites =NULL;
	delete[] sources;
	sources =NULL;

	if(extra){
		delete extra;
		extra =NULL;
	}
};

void Animation::release(){

	unsigned int i;
	for(i =0; i<nFrames; i++){

		delete frames[i];
		frames[i] =NULL;
		sprites[i]->release();
	}
}

Animation::Animation( const Animation &in )
{
	unsigned int i;

	nFrames =0;
	frames =NULL;
	sprites =NULL;
	sources =NULL;
	extra =NULL;

	fps =in.fps;
	nFrames =in.nFrames;
	cur_frame =in.cur_frame;
	begin_time =in.begin_time;
	frames =new Frame*[nFrames];
	sprites =new Texture*[nFrames];
	sources =new Source*[nFrames];
	for(i=0; i<nFrames; i++){

		frames[i] =in.frames[i];
		sprites[i] =new Texture;
		*(sprites[i]) =*(in.sprites[i]);
		if(in.sources[i]){
			sources[i] =new Source;
			*(sources[i]) =*(in.sources[i]);
		}
		else{
			sources[i] =NULL;
		}
	}
//	if(in.extra)
//		extra =new Animation(*(in.extra));
};

